package cn.tedu.hospital.admin.server.statistics.dao.persist.repository.impl;

import cn.tedu.hospital.admin.server.common.pojo.vo.PageData;
import cn.tedu.hospital.admin.server.common.util.PageInfoToPageDataConverter;
import cn.tedu.hospital.admin.server.statistics.dao.persist.mapper.StatisticsMapper;
import cn.tedu.hospital.admin.server.statistics.dao.persist.repository.IStatisticsRepository;
import cn.tedu.hospital.admin.server.statistics.pojo.param.BadUseRatioParam;
import cn.tedu.hospital.admin.server.statistics.pojo.vo.PatientStatisticsVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 统计查询的存储库实现类
 *
 * @author java@tedu.cn
 * @version 1.0
 */
@Slf4j
@Repository
public class StatisticsRepositoryImpl implements IStatisticsRepository {

    @Autowired
    private StatisticsMapper statisticsMapper;


    @Override
    public PageData<PatientStatisticsVO> listByParam(Integer pageNum, Integer pageSize,
                                                     BadUseRatioParam badUseRatioParam) {
        log.debug("开始执行【查询病人信息列表】的数据访问，页码:{}, 每页记录数:{}, 参数:{}", pageNum, pageSize, badUseRatioParam);
        PageHelper.startPage(pageNum, pageSize);
        List<PatientStatisticsVO> list = statisticsMapper.listByParam(badUseRatioParam);
        PageInfo<PatientStatisticsVO> pageInfo = new PageInfo<>(list);
        PageData<PatientStatisticsVO> pageData = PageInfoToPageDataConverter.convert(pageInfo);
        return pageData;
    }

    @Override
    public PageData<PatientStatisticsVO> list(Integer pageNum, Integer pageSize) {
        log.debug("开始执行【查询病人信息列表】的数据访问，页码:{}, 每页记录数:{}", pageNum, pageSize);
        PageHelper.startPage(pageNum, pageSize);
        List<PatientStatisticsVO> list = statisticsMapper.list();
        PageInfo<PatientStatisticsVO> pageInfo = new PageInfo<>(list);
        PageData<PatientStatisticsVO> pageData = PageInfoToPageDataConverter.convert(pageInfo);
        return pageData;
    }
}
